﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ProjTemp.Desktop.Common.View;

namespace ProjTemp.Desktop.Common.MessageBox
{
    /// <summary>
    /// Interaction logic for MessageBox.xaml
    /// </summary>
    public partial class MessageBox : VBase
    {
        public MessageBox()
        {
            InitializeComponent();
        }

        private MessageBoxButton _buttonType;
        public MessageBoxButton ButtonType
        {
            get { return this._buttonType; }
            set
            {
                this._buttonType = value;
                this.BtnCancel.Visibility = this.BtnNo.Visibility = this.BtnOK.Visibility = this.BtnYes.Visibility = System.Windows.Visibility.Collapsed;
                switch (this._buttonType)
                {
                    case MessageBoxButton.OK:
                        this.BtnOK.Visibility = System.Windows.Visibility.Visible;
                        break;
                    case MessageBoxButton.OKCancel:
                        this.BtnOK.Visibility = this.BtnCancel.Visibility = System.Windows.Visibility.Visible;
                        break;
                    case MessageBoxButton.YesNo:
                        this.BtnNo.Visibility = this.BtnYes.Visibility = System.Windows.Visibility.Visible;
                        break;
                    case MessageBoxButton.YesNoCancel:
                        this.BtnCancel.Visibility = this.BtnNo.Visibility = this.BtnYes.Visibility = System.Windows.Visibility.Visible;
                        break;
                    default:
                        break;
                }
            }
        }

        private MessageBoxImage _imageType;
        public MessageBoxImage ImageType
        {
            get { return this._imageType; }
            set
            {
                this._imageType = value;
                var dict = new ResourceDictionary { Source = new Uri(StyleConst.IconsUriAddress) };
                switch (this._imageType)
                {
                    case MessageBoxImage.Information:
                        {
                            this.Image.Fill = new SolidColorBrush(Colors.DeepSkyBlue);
                            this.ImageVisualBrush.Visual = (Visual)dict["appbar_information_circle"];
                        }
                        break;
                    case MessageBoxImage.Question:
                        {
                            this.Image.Fill = new SolidColorBrush(Colors.DeepSkyBlue);
                            this.ImageVisualBrush.Visual = (Visual)dict["appbar_question"];
                        }
                        break;
                    case MessageBoxImage.Warning:
                        {
                            this.Image.Fill = new SolidColorBrush(Colors.Gold);
                            this.ImageVisualBrush.Visual = (Visual)dict["appbar_warning"];
                        }
                        break;
                    case MessageBoxImage.Error:
                        {
                            this.Image.Fill = new SolidColorBrush(Colors.DarkRed);
                            this.ImageVisualBrush.Visual = (Visual)dict["appbar_error"];
                        }
                        break;
                    default:
                        this.Image.Visibility = System.Windows.Visibility.Collapsed;
                        break;
                }
            }
        }

        public string Text
        {
            get { return this.TextBlock.Text; }
            set { this.TextBlock.Text = value; }
        }

        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            if (this.Container != null)
            {
                this.Container.ReturnValue = MessageBoxResult.None;
                if (sender == this.BtnOK)
                    this.Container.ReturnValue = MessageBoxResult.OK;
                else if (sender == this.BtnCancel)
                    this.Container.ReturnValue = MessageBoxResult.Cancel;
                else if (sender == this.BtnYes)
                    this.Container.ReturnValue = MessageBoxResult.Yes;
                else if (sender == this.BtnNo)
                    this.Container.ReturnValue = MessageBoxResult.No;
                this.Container.Close();
            }
        }
    }
}
